#include <string_view>
#include <utility>

struct TreeNode {
    int val;
    TreeNode* left;
    TreeNode* right;
    TreeNode() : val(0), left(nullptr), right(nullptr) {}
    TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
    TreeNode(int x, TreeNode* left, TreeNode* right) : val(x), left(left), right(right) {}
};

class Solution {
public:
    TreeNode* invertTree(TreeNode* root) {
        Invert(root);
        return root;
    }

    static void Invert(TreeNode* t) {
        if (t != nullptr) {
            Invert(t->left);
            Invert(t->right);
            std::swap(t->left, t->right);
        }
    }
};